<!--
 * @Description: 键盘事件
 * @Author: rendc
 * @Date: 2021-09-07 11:46:43
 * @LastEditors: rendc
 * @LastEditTime: 2021-09-07 12:04:56
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>键盘事件</title>
</head>

<body>
  <div></div>

</body>
<script>
  document.onkeydown = function () {
    console.log("有键被按下" + event.keyCode);

  }
  // document.onkeydown = function () {
  //   if (event.shiftKey) {
  //     console.log("shift被按下");
  //   }
  //   if (event.ctrlKey) {
  //     console.log("ctrl被按下");
  //   }
  //   if (event.altKey) {
  //     console.log("alt被按下");
  //   }
  //   if (event.metaKey) {
  //     console.log("meta被按下");
  //   }
  // }
</script>

</html>